/**
 * AjLog - The AspectJ based logging facade
 * 
 * Copyright (C) 2009 - 2010, Marko Umek. All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ajlog.core.message;

import java.util.LinkedList;
import java.util.List;

import org.ajlog.util.AjLogLogger;
import org.junit.Assert;

/**
 * SimpleMessageParserResultCollector is responsible for collecting the
 * 
 * @author Marko Umek
 * 
 */
class SimpleMessageParserResultCollector
    implements
    IMessageParserResultCollector {

    private static AjLogLogger  logger  = AjLogLogger.getLogger(IMessageParserResultCollector.class);

    private final StringBuilder result  = new StringBuilder();
    private final List<String>  varList = new LinkedList<String>();
    private final boolean       expectAppendVariable;

    SimpleMessageParserResultCollector() {
        this(false);
    }

    SimpleMessageParserResultCollector(final boolean expectVariable) {
        this.expectAppendVariable = expectVariable;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.ajlog.core.message.IMessageParserResultCollector#appendFixedMessage
     * (java.lang.String)
     */
    public void appendFixedMessage(final String fixedMessagePart) {
        logger.info("Add fixed message part '%s'", fixedMessagePart);
        this.result.append(fixedMessagePart);
    }

    /**
     * Getter for result
     * 
     * @return the result
     */
    public String getResult() {
        return this.result.toString();
    }

    /**
     * Getter for varList
     * 
     * @return the varList
     */
    public List<String> getVarList() {
        return this.varList;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.ajlog.core.message.IMessageParserResultCollector#appendVariable(java
     * .lang.String)
     */
    public boolean appendVariable(final String variable) {
        if (!this.expectAppendVariable) {
            Assert.fail("Calling of appendVariable is not expected");
        } else {
            logger.info("Add variable '%s'", variable);
            this.varList.add(variable);
        }
        return true;
    }

}
